Skip to main content
Version: 5.2.0.0

Java Compiling

Description

This section explains how the code from extended java mapping is translated to Java.

The internal used compiler is Janino. It accepts only Java 1.4 syntax. The XJava source code is translated to Java with a preprocessor. This preprocessor accepts additionally to Java 1.4 the for-loop over collections as well as XPath path expressions.

Concrete Translations

A loop of the type

for (<typ> <var>: <expr>) <statement>

is translated to

for (Iterator it = <expr>.iterator(); it.hasNext(); ) {
<typ> Varname = (<typ>)it.next();
<statement>
}

In procedural mappings, structural messages are often accessed by XPath. For that reason, all parameters of type message are unwrapped before the call of the execute() method. That means that the mapping is provided a DOM-tree for each message, and this DOM-tree can be accessed procedurally or via XPath. The DOM-tree can be fetched by the method getDocument():

Document getDocument(Message msg) throws EpiBaseException

Usually, this method is not called explicitly, but implicitly through the XPath-methods: asNode, selectR, selectChildrenR, selectL, selectChildrenL, and appendChild (view below).

Within procedural mappings, XPath expressions of the type:

$<variable>/<RelativeLocationPath>

can be used. <RelativeLocationPath> is defined by the syntax specified in the XPath 1.0 specification.

An expression of the type:

$<variable>/<RelativeLocationPath>

is translated as follows:

  • If the XPath expression is on the left side of an assignment, like:

    $<variable>/<RelativeLocationPath> = <expr>

    then the following Java statement is created:

    assign(selectL(<variable>, "<xpath>"), <expr>);

    Typically, expressions like that are used to build up the target document, e.g.:

    $var/dst:record/dst:feld = "xy"
  • If the XPath expression is not on the left side of an assignment, the following Java statement is created:

    selectR(<variable>, "<xpath>")

The method selectR (and thereby all XPath expressions that are used as expressions and not as assignment targets) provide a NodeSet.

A loop of the type:

for (<typ> <var>: $VAR/<xpath>) <statement>

is translated to:

for (Iterator it = selectR(VAR, "<xpath>").iterator(); it.hasNext(); ) {
<typ> Varname = (<typ>)it.next();
<statement>
}

That means it is possible to directly iterate through the NodeSet that is provided by an XPath expression. Typically, a corresponding loop will look like:

select (Node node1: $VAR/src:record/src:child) {
...
}

The call:

appendChild($name/<rpath>/<p>:<ln>)

is translated to:

appendChild(selectL(name, <rpath>), <namespace>, "<ln>")